#include "utils.h"
#include <math.h>

/* Definition de constantes */
#define INNER_RADIUS 0.0
#define OUTER_RADIUS 5.0
#define NB_OF_SEGMENTS 32

/* Variables globales */
GLuint disqueDL = 0;

void definirCouleurCourante(float r, float v, float b)
{
    glColor4f(r,v,b, 0.6f);
}

void affichePointCarre(float x, float y)
{
    glBegin(GL_POINTS);
        glVertex2f(x,y);
    glEnd();
}
void affichePointCarreTab(float * p)
{
    glBegin(GL_POINTS);
        glVertex2fv(p);
    glEnd();
}

void afficheLigne(float x1, float y1, float x2, float y2)
{
    glBegin(GL_LINES);
        glVertex2f(x1, y1);
        glVertex2f(x2, y2);
    glEnd();
}

void afficheLigneTab(float * p1, float * p2)
{
    glBegin(GL_LINES);
        glVertex2fv(p1);
        glVertex2fv(p2);
    glEnd();
}

void trace_disque(int n)
{
	int i;
    GLfloat radius = OUTER_RADIUS; 
    GLfloat twoPi = 2.0f * M_PI;
	
	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(0.0, 0.0);
	for(i = 0; i <= n; i++) 
	{ 
		glVertex2f(radius * cos(i *  twoPi / n),
				   radius* sin(i * twoPi / n));
	}
	glEnd();
	
	
}

void creeDL()
{
    if(!disqueDL)
    {
        disqueDL = glGenLists(1);
        glNewList(disqueDL, GL_COMPILE);
        trace_disque(32);
        glEndList();    
	}
}

void affichePointDisque(float x, float y)
{
    glPushMatrix();
    glTranslatef(x,y, 0.0f);
    glCallList(disqueDL);
    glPopMatrix();
}

void affichePointDisqueTab(float * p)
{
    glPushMatrix();
    glTranslatef(p[0], p[1], 0.0f);
    glCallList(disqueDL);
    glPopMatrix();
}
